/* eslint valid-jsdoc: "off" */

'use strict';

const path = require('path')


/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1687238929896_3700';

  config.middleware = ['robot', 'error', 'auth',];

  config.robot = {
    ua: [/Baiduspider/i],
  }

  config.mongoose = {
    client: {
      url: 'mongodb://127.0.0.1:27017/egg',
      options: {},
    },
  }

  config.assets = {
    publicPath: '/public/',
    devServer: {
      debug: false,
      command: 'roadhog dev',
      port: 8000,
      env: {
        BROWSER: 'none',
        ESLINT: 'none',
        SOCKET_SERVER: 'http://127.0.0.1:8000',
        PUBLIC_PATH: 'http://127.0.0.1:8000',
      },
    },
  }

  config.view = {
    defaultViewEngine: 'nunjucks',
    mapping: {
      '.tpl': 'nunjucks',
    },
  }

  config.assets = {
    publicPath: '/public/',
  }

  config.static = {
    prefix: '/',
    dir: path.join(appInfo.baseDir, 'app/public'),
  }

  config.jwt = {
    secret: 'your-secret-zwq',
    expiresIn: '48h',
  }

  config.security= {
      csrf : {
        enable: false,
        headerName: 'Authorization',// 自定义请求头
      }
  }

  // config.cors = {
  //   origin: '*',
  //   allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH',
  // }

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  config.cors = {
    // 任何地址都可以访问
    origin:"*",
    // 指定地址才可以访问
    // origin: 'http://localhost:8080',
    allowMethods: 'GET,PUT,POST,DELETE',
    // cookie跨域配置
    credentials: true
  }

  return {
    ...config,
    ...userConfig,
    mongoose: {
      client: {
        url: 'mongodb://127.0.0.1:27017/egg',
        options: {},
      },
    },

  };
};

